package com.li.controller;


import com.li.pojo.dto.ContractDto;
import com.li.pojo.dto.ContractPageDto;
import com.li.pojo.po.Contract;
import com.li.pojo.po.PageResult;
import com.li.pojo.po.Result;
import com.li.service.ContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合同 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-14
 */
@Slf4j
@RestController
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    private ContractService contractService;

    //添加合同
    @PostMapping
    public Result addContract(@RequestBody ContractDto contractDto){
        contractService.addContract(contractDto);
        return Result.success();
    }

    //分页查询
    @GetMapping("/list")
    public PageResult findByPage(ContractPageDto pageDto){
        PageResult page=contractService.findByPage(pageDto);
        return page;
    }

    //查看合同详情--有问题
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Contract contract =contractService.findById(id);
        return Result.success(contract);
    }

    //回显合同
    @GetMapping("/detail/{id}")
    public Result returnById(@PathVariable Integer id){
        Contract contract = contractService.findById(id);
        return Result.success(contract);
    }

    //修改合同
    @PutMapping
    public Result updateContract(@RequestBody ContractDto contractDto){
        contractService.updateContract(contractDto);
        return Result.success();
    }

    //商机转合同
    @PutMapping("changeContract/{id}")
    public Result changeContract(@PathVariable Integer id,@RequestBody ContractDto contractDto){
        contractService.changeContract(id,contractDto);
        return Result.success();
    }
}
